package com.ticket.sass.provider.dto.output.film;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

/**
 * @author ywb
 * @date 2024-01-10 11:22
 */
@Data
@ApiModel(description = "电影发行版本输入")
public class FilmVersionOutput {
    @ApiModelProperty(value = "发行版本", required = true)
    private String name;
    
    @ApiModelProperty(value = "影片编码", required = true)
    private String code;
    
    @ApiModelProperty(value = "影片编码", required = true)
    private String version;
    
    @ApiModelProperty(value = "", required = true)
    private String publishDate;
    
    public FilmVersionOutput() {
    }
    
    public FilmVersionOutput(String name, String code, String version, String publishDate) {
        this.name = name;
        this.code = code;
        this.version = version;
        // 将时间戳转换为日期格式字符串
        this.publishDate = timestampToDateString(publishDate);
    }
    
    private String timestampToDateString(String timestamp) {
        // 将字符串类型的时间戳转换为 long 类型
        long epochSeconds = Long.parseLong(timestamp);
        
        // 根据时间戳创建 Instant 实例
        Instant instant = Instant.ofEpochSecond(epochSeconds);
        
        // 将 Instant 转换为 LocalDateTime，使用默认时区
        LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        
        // 格式化日期
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        return dateTime.format(formatter);
    }
}

